#include <iostream>
#include <string>
#include <vector> 
#include <sstream>

using namespace std;

bool Simple(int n)
{
    int k=2;
	while ( (k*k<=n)&&(n%k!=0) )
	{
        k+=1;
	}
    return (k*k>n);
}

double getNumber(string s)
{
	int num=0;
	if (s == "zero") num=0;
	if (s == "one") num=1;
	if (s == "two") num=2;
	if (s == "three") num=3;
	if (s == "four") num=4;
	if (s == "five") num=5;
	if (s == "six") num=6;
	if (s == "seven") num=7;
	if (s == "eight") num=8;
	if (s == "nine") num=9;
	
	return num;
}


int main()
{
	bool k;
	string input;
	
	getline(cin,input);

	string tmp;
	stringstream ss(input);
	vector <string> words;
		 
	while (getline(ss,tmp, ' '))
	{
		words.push_back(tmp);
    } 

	if ((words.size()<3) || (words[0] == "zero") )
	{
		cout << "Wrong input";
	}
	else
	{
		int number=0;
		number = getNumber(words[0])*100+getNumber(words[1])*10+getNumber(words[2]);
		
		int num1=number;
		int num2=number;
		int num3=0;
		int num4=0;	

		if(Simple(number) == true)
			cout<< number;
		else
		{
			while (Simple(num1) == false)
			{
				num1 -= 1;
			}
			num3=num1;    
			
			while (Simple(num2) == false)
			{
				num2 += 1;
			}
			num4=num2;
    
			if(abs(number - num3) <= abs(number-num4))
				cout<< num3;
			else if (abs(number - num3) > abs(number-num4))
				cout << num4;
		}

	}
	cin.get();
}